home *** CD-ROM | disk | FTP | other *** search
/ Apple II Magazines (PO) / Nibble Volume 10, No. 03 (1989-03)(MicroSPARC)(Side A).zip / Nibble Volume 10, No. 03 (1989-03)(MicroSPARC)(Side A).po / MSG.ASM.txt < prev    next >
Text File  |  1996-12-24  |  10KB  |  254 lines

  1. ***************************
  2. * MSG Source Code         *
  3. * by  Sandy Mossberg      *
  4. * Copyright (C) 1989      *
  5. * by MicroSPARC, Inc.     *
  6. * Concord, MA 01742       *
  7. *                         *
  8. * APW Environment         *
  9. * Run under APW Shell     *
  10. ***************************
  11.            SETCOM   36               ;comment line at column 38
  12.            MCOPY    MSG.MAC          ;macro definitions file
  13.            KEEP     MSG              ;load file
  14.  
  15. MATPtr     GEQU     $00              ;ptr to Message Address Table (MAT)
  16. MTTPtr     GEQU     $04              ;ptr to char in Message Text Table (MTT)
  17. MTTPtrSave GEQU     $08              ;ptr to start of msg in MTT
  18. MsgCount   GEQU     $0C              ;entry offset in MAT
  19. MSGPOINTER GEQU     $E100C0          ;vector of Message Address Table
  20.  
  21. Msg_Code   START
  22.  
  23. ***| MAIN CODE |*************************************************
  24.  
  25. ;................................................................
  26. ;
  27. ; Equate data bank with program bank:
  28. ;
  29.            PHK
  30.            PLB
  31. ;................................................................
  32. ;
  33. ; Save current I/O configuration on stack:
  34. ;
  35.            PHA                       ;space for input device code
  36.            PushLong #0               ;space for input slot/vector
  37.            _GetInputDevice
  38.  
  39.            PHA                       ;space for input AND mask
  40.            PHA                       ;space for input OR mask
  41.            _GetInGlobals
  42.  
  43.            PHA                       ;space for output device code
  44.            PushLong #0               ;space for output slot/vector
  45.            _GetOutputDevice
  46.  
  47.            PHA                       ;space for output AND mask
  48.            PHA                       ;space for output OR mask
  49.            _GetOutGlobals
  50.  
  51. ; Set slot 3 BASIC-type text I/O:
  52.  
  53.            PushWord #0               ;BASIC device type
  54.            PushLong #3               ;Input from slot 3
  55.            _SetInputDevice
  56.  
  57.            PushWord #$FF             ;AND mask (no change)
  58.            PushWord #$80             ;OR mask (set hi bit)
  59.            _SetInGlobals
  60.  
  61.            PushWord #0               ;BASIC device type
  62.            PushLong #3               ;Output to slot 3
  63.            _SetOutputDevice
  64.  
  65.            PushWord #$FF             ;AND mask (no change)
  66.            PushWord #$80             ;OR mask (set hi bit)
  67.            _SetOutGlobals
  68.  
  69.            PushWord #0               ;init input device
  70.            _InitTextDev
  71.            PushWord #1               ;init output device
  72.            _InitTextDev
  73. ;................................................................
  74. ;
  75. ; Point at Message Address Table:
  76. ;
  77.            LDA      MSGPOINTER       ;set lo order bytes
  78.            STA      MATPtr           ; of MAT
  79.            LDA      MSGPOINTER+2     ;set hi order
  80.            STA      MATPtr+2         ; of MAT
  81.            STA      MTTPtr+2         ; and MTT
  82.            STA      MTTPtrSave+2
  83.            STZ      MsgCount         ;zero entry offset for MAT
  84. ;................................................................
  85. ;
  86. ; Point at Message Text Table:
  87. ;
  88. SetMTTPtr  LDA      MsgCount
  89.            CMP      #$00FE           ;254 messages in MTT
  90.            BCS      Exit             ;all messages printed so exit
  91.            ASL      A                ;double index to 2-byte entries
  92.            TAY                       ; in MAT and transfer to Y-reg
  93.            LDA      [MATPtr],Y       ;get address of 1st message in MTT
  94.            STA      MTTPtr           ; and save in both
  95.            STA      MTTPtrSave       ; ptrs to MTT
  96. ;................................................................
  97. ;
  98. ; Print message on screen (lifted from Visit Monitor):
  99. ;
  100. ; Print individual characters:
  101.  
  102.            JSR      PrintCount       ;print message number
  103.            SEP      #$70             ;set m,x,v flags
  104.            LONGA    OFF              ; 8-bit accum and memory
  105.            LONGI    OFF              ; 8-bit index
  106.            LDA      [MTTPtr]         ;get 1st char in message
  107.            BEQ      BumpPtr          ;zero keeps v-set for MouseText
  108.            CMP      #$20
  109.            BCC      Repeat           ;repeat signal encountered
  110.            CLV                       ;v-clear signals no MouseText
  111. NextChar   LDA      [MTTPtr]         ;get next char in message
  112.            BEQ      EndMsg           ;end of message
  113.            CMP      #$20
  114.            BCC      Repeat           ;repeat signal encountered
  115.            BVS      CharOut          ;allow MouseText
  116.            BMI      CharOutEnd       ;print last char in message
  117.            ORA      #$80             ;disallow MouseText
  118. CharOut    JSR      PrintChar        ;output char
  119. BumpPtr    INC      MTTPtr           ;point to next char
  120.            BNE      NextChar
  121.            INC      MTTPtr+1
  122.            BRA      NextChar
  123.  
  124. ; End message:
  125.  
  126. CharOutEnd JSR      PrintChar        ;output final char in message
  127. EndMsg     JSR      PrintCode        ;show raw message code
  128.            BCS      Exit             ;abort signal given
  129.            INC      MsgCount         ;point to next MAT entry
  130.            BRA      SetMTTPtr        ;back for another message
  131.  
  132. ; Print repeat characters:
  133.  
  134. Repeat     TAY                       ;Y-reg counts repetitions of next char
  135.            INC      MTTPtr           ;point to next char
  136.            BNE      RepeatChar
  137.            INC      MTTPtr+1
  138. RepeatChar LDA      [MTTPtr]         ;get char to repeat
  139.            PHY                       ;save counter
  140.            BVS      RepeatOut        ;allow MouseText
  141.            ORA      #$80             ;disallow MouseText
  142. RepeatOut  JSR      PrintChar        ;output repeat char
  143.            PLY                       ;retrieve counter
  144.            DEY                       ;reduce count
  145.            BNE      RepeatChar       ;keep keep repeating
  146.            BRA      BumpPtr          ;exit repeat loop
  147. ;................................................................
  148. ;
  149. ; Restore entry I/O configuration and exit program:
  150. ;
  151. Exit       LONG                      ;clear m,x flags
  152.            _SetOutGlobals            ;input parameters on stack
  153.            _SetOutputDevice
  154.            _SetInGlobals
  155.            _SetInputDevice
  156.            PushWord #0               ;init input device
  157.            _InitTextDev
  158.            PushWord #1               ;init output device
  159.            _InitTextDev
  160.            RTL
  161.  
  162. ***| SUBROUTINES |***********************************************
  163.  
  164. ;................................................................
  165. ;
  166. ; Print character:
  167. ;
  168. PrintChar  PHP                       ;save entry status
  169.            PHY                       ;save Y-counter
  170.            LONG                      ;clear m,x flags
  171.            AND      #$00FF           ;zero hi byte
  172.            CMP      #$0040
  173.            BCC      PCh1             ;not a MouseText char
  174.            CMP      #$0060
  175.            BCS      PCh1             ;not a MouseText char
  176.            PHA                       ;codes $40-$5F signify
  177.            WRITESTR MTextOn          ; MouseText chars so
  178.            PLA                       ; turn on MouseText mode
  179. PCh1       WRITECH                   ;output char
  180.            WRITESTR MTextOff         ;disable MouseText mode
  181.            SHORT                     ;set m,x flags
  182.            PLY                       ;restore Y-counter
  183.            PLP                       ;restore status
  184.            RTS
  185. ;................................................................
  186. ;
  187. ; Print raw message code:
  188. ;
  189. ; Print hex characters:
  190.  
  191. PrintCode  LONG                      ;clear m,x flags
  192.            WRITECH  #$9D             ;clear to end of line
  193.            WRITELN                   ;print CR
  194. PCo1       LDA      [MTTPtrSave]     ;get message char
  195.            AND      #$00FF           ;zero hi byte
  196.            PHA                       ;hex number
  197.            PushLong #HexNum          ;ptr to ASCII result
  198.            PushWord #2               ;length of ASCII string
  199.            _Int2Hex                  ;get ASCII of hex number
  200.            PushLong #HexNum          ;ptr to ASCII number
  201.            _WriteCString             ;print error code
  202.            INC      MTTPtrSave       ;bump ptr to message char
  203.            LDA      MTTPtrSave
  204.            CMP      MTTPtr           ;have we reached end of message?
  205.            BCC      PCo1             ;no, back for
  206.            BEQ      PCo1             ; another char
  207.  
  208. ; Check for ESC abortion:
  209.  
  210.            WRITELN                   ;print CR
  211.            WRITELN                   ;print CR
  212.            PHA                       ;space for result
  213.            PushWord #0               ;no echo
  214.            _ReadChar                 ;get keypress
  215.            PLA                       ;retrieve char
  216.            AND      #$00FF           ;zero hi byte
  217.            CMP      #$009B           ;ESC char
  218.            BEQ      PCo2             ;CS = abort program
  219.            CLC                       ;CC = continue to next message
  220. PCo2       RTS
  221. ;................................................................
  222. ;
  223. ; Print message number:
  224. ;
  225. PrintCount WRITECH  #$8F             ;set inverse text mode
  226.            WRITESTR #' Message Number:'
  227.            LDA      MsgCount         ;get MAT offset
  228.            INC      A                ;bump to get message number
  229.            PHA                       ;line number
  230.            PushLong #DecMsgNum       ;ptr to ASCII result
  231.            PushWord #3               ;length of ASCII string
  232.            PushWord #0               ;unsigned number
  233.            _Int2Dec                  ;get ASCII of decimal number
  234.            PushLong #DecMsgNum       ;ptr to ASCII number
  235.            _WriteCString             ;print line number (right justified)
  236.            WRITECH  #$8E             ;set normal text mode
  237.            WRITELN  #' '             ;kill inverse mode
  238.            WRITELN                   ;print CR
  239.            RTS
  240.  
  241. ***| STORAGE |***************************************************
  242.  
  243. HexNum     DS       2                ;ASCII C-string of hex number
  244.            DC       H'A0 00'         ;1 space + zero terminator
  245.  
  246. DecMsgNum  DS       3                ;ASCII C-string of decimal number
  247.            DC       H'A0 00'         ;1 space + zero terminator
  248.  
  249. MTextOn    DC       H'02 8F 9B'      ;length byte + enable MouseText
  250.  
  251. MTextOff   DC       H'02 8E 98'      ;length byte + disable MouseText
  252.  
  253.            END
  254.